package com.whcoding.test.example.demo;

import org.junit.Test;

import java.util.Random;

/**
 * @program: spring-boot-learning
 * @description:
 * @author: whcoding
 * @create: 2022-06-27 16:18
 **/
public class HeapDemo {


	public static void main(String[] args) {
		// 返回虚拟机试图使用的最大内存
		long max = Runtime.getRuntime().maxMemory();    // 字节：1024*1024
		// 返回jvm的初始化总内存
		long total = Runtime.getRuntime().totalMemory();
		System.out.println("max=" + max + "字节	" + (max/(double)1024/1024) + "MB");
		System.out.println("total=" + total + "字节	" + (total/(double)1024/1024) + "MB");
		// 默认情况下:分配的总内存是电脑内存的1/4,初始化的内存是电脑的1/64
	}



	@Test
	public void heapOut() {
		String str="whcoding";
		while (true){
			str+=str+new Random().nextInt(888888888)+new Random().nextInt(999999999);
		}
	}

}
